<template>
  <el-row :gutter="24" class="pl80">
    <el-col>
      <h2>奖惩记录</h2>
    </el-col>
    <el-col>
      <e-table
        style="width: 98%"
        @getList="handleGetList"
        :tableData="tableData"
        :columns="columns"
        :loading="loading"
        :total="total"
      />
    </el-col>
  </el-row>
</template>

<script>
import { getSession } from '@/utils/util'
import { getReward } from '@/api/archives'

export default {
  data() {
    return {
      tableData: [],
      loading: false,
      columns: [
        {
          label: '考评项目类别名称',
          prop: 'eval_type_name'
        },
        {
          label: '考评项目名称',
          prop: 'eval_item_name'
        },
        {
          label: '考评项目内容',
          prop: 'eval_item_content'
        },
        {
          label: '奖惩值',
          prop: 'reward_value'
        },
        {
          label: '考评标准',
          prop: 'standard'
        },
        {
          label: '奖惩时间',
          prop: 'eval_date'
        },
        {
          label: '备注',
          prop: 'remark'
        }
      ],
      total: 1,
      queryParam: {
        pageSize: 10,
        pageNo: 1
      },
      userRow: {}
    }
  },
  created() {
    if (this.$route.query.userRow) {
      this.userRow = JSON.parse(this.$route.query.userRow)
    } else {
      this.userRow = getSession('userRow')
    }

    this.handleGetList({ userId: this.userRow.userId })
  },
  methods: {
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await getReward(this.queryParam)
      console.log('reward res', res)

      if (res.data && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
